Skip to content

6l: call dwarfaddfrag when registering D_FILE symbols#142

Merged
staalmannen merged 1 commit into
mainfrom
claude/upgrade-ape-c-library-mmZGd
May 22, 2026
Merged

6l: call dwarfaddfrag when registering D_FILE symbols#142
staalmannen merged 1 commit into
mainfrom
claude/upgrade-ape-c-library-mmZGd

Conversation

@staalmannen

Copy link
Copy Markdown
Owner

ftab (the file fragment table used by dwarf.c's decodez()) was never populated, causing every z entry lookup to fail with "corrupt z entry". Register each new SFILE symbol's fragment string into ftab via dwarfaddfrag() at the same point histgen is assigned.

https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs

ftab (the file fragment table used by dwarf.c's decodez()) was
never populated, causing every z entry lookup to fail with
"corrupt z entry". Register each new SFILE symbol's fragment
string into ftab via dwarfaddfrag() at the same point histgen
is assigned.

https://claude.ai/code/session_01WGAwvvTwDg2yknFkmZ3qzs
@staalmannen staalmannen merged commit 5109c89 into main May 22, 2026
1 check passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces DWARF debugging support to the 6l linker by including the dwarf.h header and invoking dwarfaddfrag during SFILE symbol processing. A potential out-of-bounds read was identified when accessing the symbol name, and a check was suggested to ensure the string is not empty before offsetting the pointer.

Comment thread sys/src/cmd/6l/obj.c
histgen++;
s->type = SFILE;
s->value = histgen;
dwarfaddfrag(s->value, s->name+1);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The call to dwarfaddfrag uses s->name+1 to skip the type prefix (typically 'z' or 'f'). While SFILE symbols in this context are expected to have such a prefix, if s->name were an empty string, this would result in an out-of-bounds read. Adding a check for the string length ensures robustness against malformed object files.

				if(s->name[0] != '\0')
					dwarfaddfrag(s->value, s->name+1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants